home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-01
/
ohlutil.zip
/
CP-AUX.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-05-23
|
3KB
|
118 lines
/* cp-aux.c -- file copying (auxiliary routines)
Copyright (C) 1989, 1990 Free Software Foundation.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Written by Torbjorn Granlund, Sweden (tege@sics.se).
*/
#include <stdio.h>
#include "cp.h"
extern char *program_name;
void
usage (reason)
char *reason;
{
if (reason != NULL)
fprintf (stderr, "%s: %s\n", program_name, reason);
fprintf (stderr, "\
Usage: %s [-bdfioprvR] [-S backup-suffix] [-V {numbered,existing,simple}]\n\
[+backup] [+no-dereference] [+force] [+interactive] [+one-file-system]\n\
[+preserve] [+recursive] [+verbose] [+suffix backup-suffix]\n\
[+version-control {numbered,existing,simple}] source dest\n\
\n\
%s [-bdfioprvR] [-S backup-suffix] [-V {numbered,existing,simple}]\n\
[+backup] [+no-dereference] [+force] [+interactive] [+one-file-system]\n\
[+preserve] [+recursive] [+verbose] [+suffix backup-suffix]\n\
[+version-control {numbered,existing,simple}] source... directory\n",
program_name, program_name);
exit (2);
}
char *
xmalloc (size)
unsigned size;
{
char *x = malloc (size);
if (x == 0)
error (1, 0, "virtual memory exhausted");
return x;
}
char *
xrealloc (ptr, size)
char *ptr;
unsigned size;
{
char *x = realloc (ptr, size);
if (x == 0)
error (1, 0, "virtual memory exhausted");
return x;
}
char *
str_cpy (s1, s2)
char *s1;
char *s2;
{
while ((*s1++ = *s2++) != '\0')
;
return s1 - 1;
}
int
yesno ()
{
int c, t;
fflush (stderr);
c = t = getchar ();
while (t != EOF && t != '\n')
t = getchar ();
return c == 'y' || c == 'Y';
}
int
is_ancestor (sb, ancestors)
struct stat *sb;
struct dir_list *ancestors;
{
while (ancestors != 0)
{
if (ancestors->ino == sb->st_ino && ancestors->dev == sb->st_dev)
return 1;
ancestors = ancestors->parent;
}
return 0;
}
/* Remove trailing slashes from PATH; they cause some system calls to fail. */
void
strip_trailing_slashes (path)
char *path;
{
int last;
last = strlen (path) - 1;
while (last > 0 && path[last] == '/')
path[last--] = '\0';
}